﻿Ext.namespace('iOS.App.Photos');

Ext.define('PhotosBooks', {
	extend : 'BaseView',

	statics : {
		BaseCls       : 'list-view',
        ListContainer : 'list-container',
        ListCls       : 'ios-list',
        ListContent   : 'list-content',
        PicsRow       : 'pics-row',
        DragContainer : 'drag-container',
        PhotosPics    : 'photos-pics',
        PhotosPic     : 'photos-pic',
        AppCard       : 'photos-card',
        BooksFooter   : 'books-footer'
	},

	_picsURL : 'resource/images/apps/photos/',

	_attachEventListener: function(){
		this.callParent();
		var sttc = this.self;
		this.getElCacheByCls(sttc.PhotosPics).on('rangeclick', function(){
			iOS.ViewManager.notify(sttc.AppCard, 'changeCard', [sttc.PhotosPic]);
		});
	},

	_initInnerDom: function(){
		var sttc 	 = this.self,
			htmlData =
			'<div class="' + sttc.DragContainer + '">' +
				'<div class="' + sttc.PicsRow + '">' +
					'<div class="' + sttc.PhotosPics + '"></div>' +
					'<div class="' + sttc.PhotosPics + '"></div>' +
					'<div class="' + sttc.PhotosPics + '"></div>' +
					'<div class="' + sttc.PhotosPics + '"></div>' +  
				'</div>' +
				'<div class="' + sttc.PicsRow + '">' +
					'<div class="' + sttc.PhotosPics + '"></div>' + 
				'</div>' +
				'<div class="' + sttc.BooksFooter + '">69张照片</div>' +
			'</div>'
		this.getElCache().html(htmlData);
		var config   = {
            direction  : 'vertical',
            bounces    : 'vertical'
        };
        $.scrollView(this.getElCacheByCls(sttc.DragContainer), config); 
	},

	_afterRender: function(){
		this.callParent();
		this._setBooksThumbnails();
	},

	_setBooksThumbnails: function(){
		function getURL(i){
            return  'url(' + baseURL + 'ios-photos-books' + i + '.png)';
        }
        var sttc    = this.self,
            books   = this.getElCacheByCls(sttc.PhotosPics),
            baseURL = this._picsURL;
        for(var i   = 0; i < books.length; i++){
            books.eq(i).css('backgroundImage', getURL(i));
        }
	}
});

iOS.App.Photos.PhotosBooks = PhotosBooks;